#include<unistd.h>
#include<stdio.h>
#include<sys/wait.h>
#include<sys/types.h>

int main(){		
		printf("begin:我是父进程%d,我父亲进程是%d\n",getpid(),getppid());
    pid_t id=fork();
    if(!id){
        int i=10;
        while(1){
            printf("I am child,my pid is %d,my father pid is %d\n",getpid(),getppid());
            sleep(1);
        }   
    }else{
        printf("I am father,my pid is %d,my father pid is %d\n",getpid(),getppid());
        int status=0;
        pid_t id_ch=0;
        do{
            id_ch=waitpid(-1,&status,WNOHANG);
            printf("正在等待子进程\n");
            sleep(1);
        }while(!id_ch);

        if(id_ch<0){
           printf("返回错误\n");    
        }else{
            printf("等待返回子进程的pid：%d\n",id_ch);
        }
    }
    return 0;
}
